package com.fifth.home.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Article;
import com.fifth.home.service.IArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第五组
 * @since 2022-09-08
 */
@RestController
@RequestMapping("/home/article")
@Api(tags = "底部文章的文章管理相关接口")
public class ArticleController {
    @Autowired
    private IArticleService articleService;

    /**
     * 根据底部文章id查询文章管理信息
     * @param navId
     * @return
     */
    @PostMapping("getArticleByNavId/{navId}")
    @ApiOperation("根据底部文章ID查询文章管理接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "底部文章id",name = "navId",dataType = "String",required = true)
            }
    )
    public CommonResult getArticleByNavId(@PathVariable String navId){
        return  articleService.selectByNavId(navId);
    }

    /**
     * 修改文章管理信息
     * @return
     */
    @PostMapping("updateArticleByNavId")
    @ApiOperation("根据底部文章ID修改文章管理接口")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "文章管理实体类",name = "article",dataType = "Article",required = true)
            }
    )
    public CommonResult updateArticleByNavId(@RequestBody Article article){
        return  articleService.updateArticle(article);
    }

    /**
     * 根据parentid查看对应的文章内容信息
     * @param id  这里是parentid
     * @return
     */
    @ApiOperation("根据底部文章ID查询文章管理接口(前端调用)")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "底部文章id，也就是parentid",name = "id",dataType = "String",required = true)
            }
    )
    @PostMapping("getAllQianArticle/{id}")
    public CommonResult getAllQianArticle(@PathVariable String id){
        return articleService.selectByNavId(id);
    }
}
